package com.gdut.simple.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.data.entity.Wiki;
import com.gdut.simple.view.activity.WebActivity;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

public class WikiAdapter extends AbsRecyclerAdapter<Wiki> {

    public WikiAdapter(Context context, List<Wiki> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mInflater.inflate(R.layout.layout_wiki_item, parent, false));
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        final ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.title.setText(mData.get(position).getTitle());
        viewHolder.desc.setText(mData.get(position).getDescription());
        Picasso.with(mContext).load(mData.get(position).getIcon()) .config(Bitmap.Config.RGB_565).into(viewHolder.image);
    }

    static class ItemViewHolder extends AbsViewHolder {

        TextView title;
        TextView desc;
        ImageView image;

        public ItemViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.id_wiki_title);
            desc = (TextView) itemView.findViewById(R.id.id_wiki_desc);
            image = (ImageView) itemView.findViewById(R.id.id_wiki_image);
        }
    }
}
